var CONST = require('../../../utils/const');
var retUtil = require('../../../utils/retUtil');
var CONFIG = require('../../../../../common/config');
/*
* 权限检测中间件
*
* @author 王俊
* @date 2018-07-02
*
* */
function permission(req, res, next) {
    var check_url = ["/yjx/v1/promoter/users/checkBalkMobileCode","/yjx/v1/promoter/users/getBackMobileVerCode","/yjx/v1/promoter/users/deleteUserInfo","/yjx/v1/company/users/middleStageLogin"];
    var uri = req.originalUrl.split('?')[0];
    for(var i=0;i<check_url.length;i++){
        if (uri.indexOf(check_url[i]) >=0) {
            return next();
        }
    }

    var user = req.session[CONST.SESSION_USER];
    if(!user) {
        return retUtil.ret_err_json('权限不足', res);
    }
    next();
}

module.exports = permission;